package com.cgnpc.scp.manager.controller;

import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.manager.mybatis.entity.Systeminfo;
import com.cgnpc.scp.manager.service.SystemInfoService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/******************************
 * 用途说明: 系统应用列表
 * 作者姓名: heyachen
 * 创建时间: 2020/08/06 23:04
 ******************************/
@Controller
@RequestMapping("/scp/data/systeminfo")
public class SystemInfoController {


    private static final Logger LOGGER = LoggerFactory.getLogger(SystemInfoController.class);
    @Autowired
    private MessageSource messageSource;

    @Autowired
    private SystemInfoService systemInfoService;

    /**********************************
     * 用途说明: 保存信息
     * 参数说明 有ID更新。无ID保存
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="保存常用系统设置")
    @UBA(module = "后台管理", action = "保存系统信息", channel = OperatorType.Button)
    @RequestMapping(value = "/saveOrUpdate", method = {RequestMethod.POST})
    @ResponseBody
    public Object saveOrUpdate(HttpServletRequest request, @RequestBody Systeminfo systeminfo) {
        try{
            int updateRows=systemInfoService.saveOrUpdate(systeminfo);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,updateRows);
        }catch (Exception e){
            LOGGER.error("SystemInfoController saveOrUpdate error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }
    /**********************************
     * 用途说明: 删除信息
     * 参数说明 ids
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="删除信息")
    @UBA(module = "后台管理", action = "删除系统信息", channel = OperatorType.Button)
    @RequestMapping(value = "/del", method = {RequestMethod.POST})
    @ResponseBody
    public Object del(HttpServletRequest request, @RequestBody List<String> ids) {
        try{
            int delete = systemInfoService.del(ids);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,delete);
        }catch (Exception e){
            LOGGER.error("SystemInfoController del error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }
    /**********************************
     * 用途说明: 查询 全部
     * 参数说明 systemconfig
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="查询全部")
    @UBA(module = "后台管理", action = "查询全部系统信息", channel = OperatorType.Page)
    @RequestMapping(value = "/load", method = {RequestMethod.POST})
    @ResponseBody
    public Object load(HttpServletRequest request, @RequestBody Systeminfo systeminfo) {
        try{
            List<Systeminfo> systemconfigMyPageResult = systemInfoService.load(systeminfo);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,systemconfigMyPageResult);
        }catch (Exception e){
            LOGGER.error("SystemInfoController load error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }
    /**********************************
     * 用途说明: 查询单条
     * 参数说明 systemconfig
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="查询单条")
    @UBA(module = "后台管理", action = "查看系统信息详情", channel = OperatorType.Button)
    @RequestMapping(value = "/loadByID", method = {RequestMethod.POST})
    @ResponseBody
    public Object loadByID(HttpServletRequest request, @RequestBody Systeminfo systeminfo) {
        try{
            Systeminfo systemconfigMyPageResult = systemInfoService.loadByID(systeminfo);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,systemconfigMyPageResult);
        }catch (Exception e){
            LOGGER.error("SystemInfoController loadByID error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }
    /**********************************
     * 用途说明: 分页查询
     * 参数说明 systemconfig
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="分页查询")
    @UBA(module = "后台管理", action = "系统信息分页查询", channel = OperatorType.Button)
    @RequestMapping(value = "/loadByPaging", method = {RequestMethod.POST})
    @ResponseBody
    public Object loadByPaging(HttpServletRequest request, @RequestBody Systeminfo systeminfo) {
        try{
            MyPageResult<Systeminfo> systemconfigMyPageResult = systemInfoService.loadByPaging(systeminfo);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,systemconfigMyPageResult);
        }catch (Exception e){
            LOGGER.error("SystemInfoController loadByPaging error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

}
